<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <link
            rel="stylesheet"
            type="text/css"
            href="../node_modules/mocha/mocha.css"
        />
        <script src="../node_modules/mocha/mocha.js"></script>
    </head>

    <body>
        <div id="mocha"></div>
        <!-- 
<script
    type="systemjs-importmap"
    src="https://hostname.invalid/importmap.json"
></script>
<script
    type="systemjs-importmap"
    src="fixtures/browser/importmap-invalid.json"
></script>
<script
    type="systemjs-importmap"
    onerror="retryImportMap()"
    src="fixtures/browser/importmap-invalid.json"
></script>
<script
    type="systemjs-importmap"
    src="fixtures/browser/importmap.json"
    integrity="sha384-+t/f9i0vQYwxmcczlIpgCCTQz2mA1sMGYGErJ4fZb/Lcx/yYrFSiedO0XpSIX8oX"
></script>
 -->

        <script type="module">
            import { SystemJS } from "../dist/s.js";
            import "https://cdn.jsdelivr.net/npm/chai/chai.js";
            globalThis.System = new SystemJS();
            globalThis.assert = chai.assert;

            mocha.setup("bdd");

            globalThis.suite = globalThis.describe;
            globalThis.test = globalThis.it;
            globalThis.baseURL = location.href.replace(
                /\/test\/test.html.*/,
                "/"
            );
            globalThis.rootURL = location.origin + "/";
            System.setBaseUrl(globalThis.baseURL);
            console.log(globalThis.baseURL);
            console.log(globalThis.rootURL);

            const importsMap = await fetch(
                "./fixtures/browser/importmap.json"
            ).then((res) => res.json());
            System.extendImportMap(
                importsMap,
                new URL(
                    "./fixtures/browser/importmap.json",
                    location.href
                ).toString()
            );

            // * 预加载 JS 内容文本
            await [
                "./test/fixtures/browser/systemjs-module-early.js",
                "./test/fixtures/browser/systemjs-module-script.js",
                "./test/fixtures/browser/auto-import.js",
                "./test/fixtures/browser/systemjs-module-script2.js",
            ].reduce((col, cur) => {
                return col.then(() => System.import(cur));
            }, Promise.resolve());

            function importNext(name) {
                return () => import(name);
            }

            function importSeries() {
                var promise = Promise.resolve();

                for (var i = 0; i < arguments.length; i++) {
                    promise = promise.then(importNext(arguments[i]));
                }

                return promise;
            }

            // 测试文本

            await importSeries("./browser/core.js");
            "./browser/amd.js",
                "./browser/named-exports.js",
                "./browser/transform.js",
                "./browser/named-register.js",
                "./browser/dynamic-import-maps.js";
            mocha.checkLeaks();
            console.log("all down");
            mocha.run();
        </script>
    </body>
</html>
